home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 26
/
Cream of the Crop 26.iso
/
utility
/
fortn707.zip
/
FORTUNE.DOC
< prev
next >
Wrap
Text File
|
1997-07-31
|
29KB
|
598 lines
FORTUNE.DOC 1 Jul 31, 1997
WIN95 AND WINNT NOTICE: As with most DOS-based utilities, this program doesn't
understand the weird subdirectories, long filenames, invalid characters that
are possible under Windows 95 and Windows/NT. Both operating systems alias
long filenames into names like MYFILE~1.TXT and you will need to specify the
aliased versions of file names to process them. Under some file structure
systems in NT, the program may not work at all.
The FORTUNE.EXE program adds some tuning features to the DOS FOR command (FOR
tune, fortune, what the heck). These features can in some way be applied to
commands accepting regular DOS wildcards. Features include:
* Results of command are written to a batch file which you can review before
you run it. Lets you subsequently edit it if desired and lets you see
exactly what commands will happen when you run it.
* Can execute the commands interactively if they don't require that much
memory to run.
* Allows embedded redirection indicators in a command (see next example).
* Lets you separate the file name and file extension. For example:
FORTUNE IN (*.TXT) DO SORT %[ %A %] %1*.SOR
* Lets you identify individual characters in the the file name and extension.
For example:
FORTUNE IN (*.TXT) DO RENAME %A (%1%2%3%4%5%6).*
* Lets you specify a character other than "%" for the delimiter so you can
avoid worrying about different syntax in batch command vs command line.
* Can have the batch file pause after each command so results can be
reviewed.
* Allows for incrementation in the file names. For example:
FORTUNE IN (*.TXT) /+2 DO COPY %A %1*.%0001
* Allows multiple statements on one command line.
* Allows you to recurse through child subdirectories. For example:
FORTUNE IN (\*.TXT) /S DO COPY %A D:\BACKUPS
Another example involves getting rid of an annoying hidden file that some
utility might keep dumping on your hard disk. For example, I love the ACD
Systems Ltd's ACD See program. It lets you view lots of different graphic
files under Windows. Unfortunately, it typically creates a hidden file
called DESCRIPT.ION in each subdirectory that you visit with it. This is
annoying. So to get rid of them all, you can issue the command:
FORTUNE IN \DESCRIPT.ION /S /ATTR=H DO ATTRIB %a -H $$ DEL %a
Another example. Delete all batch files from the subdirectory forward:
FORTUNE *.BAT /S DEL %A
* Allows up to 10 file specifications from consideration.
* Allows you to limit files processed based on attributes, filesize, or
filedate.
* Lets can do those tough PKZIP commands that you always wanted to do. Like
compress all *.FLI files in your subdirectory to a ZIP of the same name as
the original file:
FORTUNE *.FLI DO PKZIP -M %R %e
Or move all WAV files into ZIP files with the same name as the WAV file
(separate ZIP for each WAV file):
FORTUNE *.WAV PKZIP -M %R %R.%E
* Allows you to use the command to create a file which contains a series of
commands including a header and footer section which can be used for some
batch functions.
* Pressing escape stops the program early.
FORTUNE.DOC 2 Jul 31, 1997
The DOS FOR command:
Quite a few DOS users are unaware of the DOS FOR command. It allows you to do
a single command over a series of files and provides an easy way to use
wildcards with commands that don't accept them. For example, if you want to
type a number of files to your screen, you can say something like:
FOR %A IN (*.TXT) DO TYPE %A
DOS looks at your IN specification and figures out what file names are covered
by that request. The request can include path information if desired and can
have multiple specification (for example, "...IN (*.TXT \BAT\*.DOC)...").
FOR then substitutes the file name itself in for whatever variable you specify
in the first parameter after "FOR" ("%A" here). This variable is a single
character (A to Z) preceded by a single percent sign (%). (If FOR is used in a
batch command, you have to use two percent signs (%%) instead.)
FOR then looks at the command following the keyword "DO" and executes that
command. If it finds the variable name in the command, it substitutes the name
of the file for that variable.
So, in the above example, if you had three *.TXT files--ABLE.TXT, BAKER.TXT,
and CHARLIE.TXT--and you ran the command, it would actually do three commands
for you:
TYPE ABLE.TXT
TYPE BAKER.TXT
TYPE CHARLIE.TXT
All in all, FOR is a *very* useful command. There are also some DOS tricks
that you can use to make the command even more useful but, frankly, I always
forget the tricks. (If someone would like to e-mail them to me, I'll throw
them in here.) In any case, even past the tricks, the FORTUNE command provides
even more features.
FORTUNE.DOC 3 Jul 31, 1997
FORTUNE wildcards and special characters:
The FORTUNE.EXE program extends the functionality of the DOS FOR command by
providing ways of splitting up the parts of the file name and manipulating the
parts. For example, someone in my office had a mess of files that had to be
renamed as an open parenthesis, followed by the first six characters of the
file name, followed by a close parenthesis. Not too terrible to handle with my
text editor but it hadn't occurred to her. Using FORTUNE, however, it's pretty
easy:
FORTUNE IN (*.TXT) DO RENAME %A (%1%2%3%4%5%6).*
And then you run the newly-created batch file (DOIT.BAT).
Similarly, someone wanted me to rename a mess of files so they had sequential
names. I had to write a program to handle it. Definitely beyond his
capabilities. Again, using FORTUNE it's pretty easy:
FORTUNE IN *.TXT DO RENAME %A %1*.%0001
And again you run the DOIT.BAT file.
Within the command (DO command), FORTUNE allows you to include a number of
indicators. The character which indicates that it's a special character is
typically "%" but you can change this with the /VAR=char option in FORTUNE. All
of the examples here use the default /VAR=% setting.
NOTE TO 4DOS AND Win95 USERS: 4DOS and Windows 95 automatically translate
paired "%" characters even if used on the command line. FORTUNE detects if you
are running under 4DOS or Win95 and changes the default /VAR=% to /VAR=@ for
you. The following examples all presume /VAR=%; mentally shift them to be "@"
instead of "%" and you'll be fine.
FORTUNE.DOC 4 Jul 31, 1997
In many cases, the indicators are case sensitive; there's a difference between
%p and %P (presuming the default /VAR=% delimiter). Typically, the lowercase
variants are cumulative. %P gives you just the path whereas %p throws in the
drive information too.
%a or %A translates into the entire file name (begins with drive,
colon, \, path, \, file root, ., file extension).
Use %R.%E if you want the filename without the drive/path info
%D translates into the drive (not followed by :)
%d translates into the drive (followed by :)
%P translates into path (not preceded or followed by \)
%p translates into path (begins with drive, colon, \, path, \)
%R translates into file name root
%r translates into file name root (begins with drive, colon, \,
path, \)
%E translates into file name extension
%e translates into file name extension (begins with drive, colon,
\, path, \, file name root, .)--same as %a
%1 to %8 characters 1 to 8 in the file name root
%X to %Z characters 1 to 3 in file name extension (case insignificant;
%X is the same as %x)
%* replaces the character with the standard "*" wildcard
%? replaces the character with the standard "?" wildcard
The standard DOS wildcards--"*" and "?"--are supported within the file name.
"...DO RENAME %A Q*.Y*" will actually generate commands with the letters filled
in (if the file name is APPLES.ARE, the command will be RENAME QPPLES.YRE).
If you want to actually write out the commands and leave in the "*" or "?"
characters, precede the wildcard characters with "%" (or with whatever
delimiter you have specified in your /VAR=x parameter). For example:
FORTUNE (*.001) DO COPY %R.0%* %R.TOP
will generate something like "COPY TN960402.0* TN960402.TOP" whereas
FORTUNE (*.001) DO COPY %R.0* %R.TOP
will generate "COPY TN960402.001 TN960402.TOP".
All other characters in the command string are passed as given.
FORTUNE.DOC 5 Jul 31, 1997
Using the above characters, if you have two files C:\AUTOEXEC.BAT and
D:\WAYNE\MYSTUFF.TXT, the various codes above translate as:
filename: C:\AUTOEXEC.BAT D:\WAYNE\MYSTUFF.TXT
%a or %A C:\AUTOEXEC.BAT D:\WAYNE\MYSTUFF.TXT
%D C D
%d C: D:
%P (null) WAYNE
%p \ D:\WAYNE\
%R AUTOEXEC MYSTUFF
%r C:\AUTOEXEC D:\WAYNE\MYSTUFF
%E BAT TXT
%e C:\AUTOEXEC.BAT D:\WAYNE\MYSTUFF.TXT
%1 A M
%2 U Y
%3 T S
%4 O T
%5 E U
%6 X F
%7 E F
%8 C (null)
%X B T
%Y A X
%Z T T
Special translations:
%[ translates into <
%] translates into >
%0nnnn incrementer field (where "nnnn" is any number of digits;
translates into a numeric field which has the same number of
digits excluding the zero after the delimiter; the first number
will be the value of "nnnn" and subsequent files will be
incremented by the value specified in the /+n or /-n parameter
(defaults to /+1): Examples: %0001 will start with "001";
%00050 will start with "0050"
FORTUNE.DOC 6 Jul 31, 1997
Using a command file for special cases:
In addition, FORTUNE supports some options that might be used outside of a
batch file. (There are also several uses for this within a batch command but I
won't go into them here. Think about it on your own.) For example, let's say
you have an FTP program and you want to log onto the site and upload all of the
*.TXT files in your subdirectory. Normally, you'd do this by typing something
like this in response to the expected prompts:
ftp
ftp.cu.nih.gov (the name of the ftp site you're logging onto)
anonymous (your userid--I know, anonymous logins aren't
trusted for uploads; use your own userid)
WayneSof@erols.com (your password)
cd pub
cd incoming
Now, for each of the files you have, you'd have to enter a command like "send
filename", typically followed by a blank line when prompted for the recipient
file name.
Finally, after you're all done, you'd typically issue a "quit" command.
Thinking about it, you can use redirection in DOS to say "FTP < filename", as
long as the lines in the text file "filename" contain all of the statements in
sequence that you need to issue.
FORTUNE lets you specify a command file which contains a "header" section
(commands to be sent beforehand), a "main" section (commands to be sent for
each filename), and a "footer" section (commands to be send afterward). Each
section is optional and may consist of up to 20 commands. In our example, your
command file (we'll call it "FORTUNE.FTP" in this case) might look like this:
/header
ftp
ftp.cu.nih.gov
anonymous
WayneSof@erols.com
cd pub
cd incoming
/main
send %A
(blank line)
/footer
quit
The commands within the "main" section are repeated for each file and can
contain all of the standard FORTUNE features for the command section.
If a section is not found, the statements are presumed to be part of the "main"
section (that is, "/main" is presumed at the start of the file).
FORTUNE.DOC 7 Jul 31, 1997
The sections can appear in any order.
To bring in the command file, specify "DO @filename" instead of "DO command".
So, your command line might be:
FORTUNE IN (*.TXT) DO @FORTUNE.FTP
This will create a DOIT.BAT file which, in fact, does not contain batch command
statements at all. If this bothers you, specify a different output file name
(using the "/AS filename" parameter) if you want. Then, to process this file
in your FTP command, use standard redirection:
FTP < DOIT.BAT
If you have /VAR=@ in effect, make it "DO @@filename" instead of "DO
@filename". For example:
FORTUNE IN (*.TXT) /VAR=@ DO @@FORTUNE.FTP
Note that using the command file feature disables processing of the FORTUNE
parameters which are specific to batch files. These ignore parameters are:
/ECHO, /-ECHO, /ABEND, /-ABEND, /P, and /-P.
In addition, you can specify a file that contains the filenames to process by
using "/IN @filename" or "IN @filename". This feature can be very handy when
/-CHECK is specified and the file itself contains file names on a remote host.
For example, this is useful if you're trying to run something like FORTUNE on
an ftp host over the Internet to issue a series of "get" commands on that host.
One disadvantage of the /-CHECK parameter is that it will not parse out the
file name at all so only %A-like requests will do any good.
Specifying parameters:
Parameters for this program can be set in the following ways. The last setting
encountered always wins:
- Read from an *.INI file (see BRUCEINI.DOC file),
- Through the use of an environmental variable (SET FORTUNE=whatever), or
- From the command line (see "Syntax" below)
Remember that DOS doesn't allow a command line to exceed 127 characters. Use
control files whenever necessary.
FORTUNE.DOC 8 Jul 31, 1997
Syntax:
FORTUNE { IN (set) | IN filespec | /IN (set) | /IN filespec | filespec }
[ /AS filename ] [ /OVERWRITE | /APPEND | /-OVERWRITE | /OVERASK ]
[ /VAR=char ] [ /DELIM=chars ] [ /+n | /-n ] [ /S ] [ /Xfilespec ] ...
[ /SIZE { GT | GE | LT | LE | EQ | NE } value ]
[ /DATE { GT | GE | LT | LE | EQ | NE } date ]
[ /ATTR=attribs ] [ /-ECHO ] [ /-ABEND ] [ /P ]
[ /RUN ] [ /PROMPT | /-PROMPT ] [ /-CHECK ] [ /-WIPE ]
[ /MONO ] [ /Iinitfile | /-I ] [ /-ENV ] [ /? ]
{ DO command | /DO command | command }
where:
"IN (set)" lets you specify the file names to be processed. Multiple file
specifications should be separated by a space or a semicolon. For
compatibility with the FORTUNE-only parameters, "IN" can be preceded by a "/"
if desired. ("IN" and "DO" are supported for compatibility with the DOS FOR
command but all FORTUNE-only parameters must begin with "/".) If only one file
specification is provided, you can skip the parentheses. You can specify
"%PATH%" (to process all files in your path) or "%PATH%;*.EXE" (to process a
given set of files from your path). (The "%" character depends on the value of
the /VAR=char paramter.) A file specification is required for FORTUNE.
You can specify an input file that contains the file list to process. This is
done using "@filename" instead of "set" or "filespec".
It's possible to leave off the "IN" (or its derivatives) as well as the
parentheses if your file specification(s) include a "\", "*", or "?" character.
For example:
FORTUNE *.BAS *.DOC DO TYPE %A
"/AS filename" tells the command the name of the batch file to create with the
resulting commands. By default, this file will be called DOIT.BAT and it will
be created in your default subdirectory.
"/OVERWRITE" says to write over any output file that's already there.
"/APPEND" says to add the new records at the end of any output file that's
already there. Since FORTUNE uses the same DOS labels every time it executes,
concatenating FORTUNE-created batch files is not recommended.
"/-OVERWRITE" says to abort if the output file exists already.
"/OVERASK" says to prompt if the output file exists already; this is the
default.
"/VAR=char" indicates the character to use as the special character indicator.
This initially defaults to "/VAR=%" under DOS and Windows 3.1 for compatibility
with the existing FOR command. It initially defaults to "/VAR=@" under 4DOS
and Windows 95 due to the way that these operating systems resolve command-line
parameters with "%" in them. If "/VAR=%" is in effect, remember that you using
a single percent sign for any command entered from the command line but you
need to double the percent signs (using "%%" instead of "%" each time) if
you're using FORTUNE from within a batch command. You can avoid this hassle by
picking another character (like /VAR=^) if you'd like.
FORTUNE.DOC 9 Jul 31, 1997
"/DELIM=chars" allows you to indicate delimiters to use between statements
within the DO command. Defaults to "/DELIM=$$". This allows you to process
multiple statements in a single FORTUNE command. For example:
FORTUNE IN *.BAS DO COPY %A \TEMP $$ TYPE \TEMP\%R.%E
Note that the number of characters can be any length (including one character).
Your only consideration is that the characters do not appear together in your
command otherwise. The characters are case insignificant ("/DELIM=newline" and
"/DELIM=NEWLine" are the same thing).
"/+n" and "/-n" allow you to specify the increment/decrement value to be used
where %0nnnn indicators are used in the command line. Defaults to "/+1".
"/S" processes the children subdirectories as well. So you could do something
like any of the following:
FORTUNE IN (\*.BAS) /S COPY %A LPT1:
FORTUNE IN (\OLD*.TXT) /S DO DELETE %A
The next example is a little bizarre. Let's say you're using an anti-virus
protection program that maintains a read-only file in each subdirectory with
all of the virus signatures for the files in that subdirectory. You decide you
no longer want to use that program again but you have a zillion of these files
and they're all read-only. The following example would search them all out,
reset them to not be read-only, and then delete them.
FORTUNE IN (\VIRCK.SIG) /S DO ATTRIB %A -R $$ DEL %a
"/Xfilespec" says to exclude certain filespecs from being considered. You can
specify up to 10 exclusion parameters but each must begin with "/X". For
example, you could process all *.BAS files except D*.BAS and E*.BAS files with:
FORTUNE IN (*.BAS) /XD*.BAS /XE*.BAS DO TYPE %A
"/SIZE xx value" says you want to limit the list of individual files to those
which meet a certain size requirement. Due to DOS's redirection commands,
relations like ">" and "<" don't work so you have to use the two-letter
abbreviations:
GT greater than >
GE greater than or equal to >=
LT less than <
LE less than or equal to <=
EQ equal to =
NE not equal to <>
Having said that, the only two you're likely to use are GT and GE. The "value"
is the size value you want tested for. So "/SPACE GT 1000000" would find all
individual files with a filesize greater than one million bytes.
"/DATE xx date" says to show only those files created before or after a given
date. As before, you have to use GT, GE, LT, LE, EQ, and NE for the relational
operator. "/DATE GE 10/01/91" would show only those files created on or after
October 1, 1991. The format for the date is determined by your system settings
(it might be "/DATE GE 10.01.91" in France).
FORTUNE.DOC 10 Jul 31, 1997
"/ATTR=attribs" allows you to specify a combination of attributes that you want
considered. You can specify any combination of R (read-only), H (hidden), S
(system), or A (archive bit). Precede any character(s) with "-" to exclude
instead of include. Unlike with the DOS DIR command, the inclusions and
exclusions are subject to "OR" conditions; /ATTR=HS will retrieve any file that
is either hidden or a system file or both. You can specify "/ATTR=ALL" to
specify that all files are to be processed. Initially defaults to /ATTR=ALL
(don't exclude any files from consideration).
"/ECHO" says to turn ECHO ON in the batch file. This will show the command
being executed before it executes. This is initially the default.
"/-ECHO" says to turn ECHO OFF in the batch file.
"/ABEND" (abnormal end) says to use standard DOS errorlevel trapping to see if
there was an error in running the command. If any non-0 errorlevel condition
is encountered (for example, an error has occurred), the batch file will branch
out, skipping the rest of the statements in the batch file and aborting. Note
that not all commands return decent errorlevel codes. COPY, for example,
doesn't set an errorlevel to indicate that the file could not be found.
"/ABEND" is the initially the default.
"/-ABEND" says to skip errorlevel testing.
"/P" (or "/PAUSE") says to add a PAUSE statement after each statement that's
executed. If you don't like what you see, you can press Ctrl-Break and get out
of the batch file.
"/-P" (or "/-PAUSE") skips the PAUSE statements. This is initially the
default.
"/RUN" says to try to run the commands interactively instead of writing out the
batch file. This only works for commands that don't take much memory (like
RENAME and COPY commands). The default is initially "/-RUN".
"/-RUN" says to write the commands out to the standard batch file. This is the
initially the default.
"/PROMPT" says to prompt you before either writing (if /-RUN being used) or
executing (if /RUN being used). You are given the choice of "Yes", "No", or
"Abort" if prompting is turned on. The default is "/PROMPT" if /RUN is
selected, otherwise "/-PROMPT".
"/-PROMPT" says to skip the prompts for each command. The default is "/PROMPT"
if /RUN is selected, otherwise "/-PROMPT".
"/CHECK" says that when an "/IN @filename" is used, verify each data set's
existence. This is initially the default.
"/-CHECK" skips the data set checking. This is useful when you're issuing
something like a series of GET commands using FTP; the data sets in the "/IN
@filename" may be on a remote host which can't be verified when FORTUNE is run.
Initially defaults to "/CHECK".
FORTUNE.DOC 11 Jul 31, 1997
"/WIPE" says to kill the batch file (for example, DOIT.BAT) after successful
completion. This produces an annoying error message ("Batch file missing") but
may be preferable to keeping the batch file around afterward. Initially
defaults to "/WIPE".
"/-WIPE" says to keep the batch file around after completion. This avoids the
ugly error message but leaves the file in your subdirectory. Initially
defaults to "/WIPE".
"/MONO" (or "/-COLOR") does not try to override screen colors. Initially
defaults to "/COLOR".
"/COLOR" (or "/-MONO") allows screen colors to be overridden. This is
initially the default.
"/Iinitfile" says to read an initialization file with the file name "initfile".
The file specification *must* contain a period. Initfiles are described in the
BRUCEINI.DOC file. Initially defaults to "/IFORTUNE.INI".
"/-I" (or "/INULL") says to skip loading the initialization file.
"/ENV" says to look for %var% occurrences in the command line and try to
resolve any apparent environmental variable references. See BRUCEINI.DOC for
more information. This is initially the default.
"/-ENV" says to skip resolving apparent %var% occurrences in the command line.
Initially defaults to "/ENV".
"/?" or "/HELP" or "HELP" shows you the syntax for the command.
"DO command" (or "/DO command" or just "command") specifies the command(s) to
be executed. For compatibility with the FORTUNE-only parameters, "DO" can be
preceded by a "/" if desired. ("IN" and "DO" are supported for compatibility
with the DOS FOR command but all FORTUNE-only parameters must begin with "/".)
A command is required. Multiple commands can be specified if they are
separated using the characters specified in the /DELIM=chars parameter. You
can also use a command file by using /DO @filename; see the previous discussion
on "Using a command file for special cases".
In most cases, the use of the "DO" (or "/DO") parameter is actually
unnecessary. The routine typically treats all of the following as identical:
FORTUNE IN (*.BAS *.DOC) DO TYPE %A
FORTUNE IN (*.BAS *.DOC) TYPE %A
FORTUNE *.BAS *.DOC TYPE %A
However, using the "DO" (or "/DO") parameter adds an extra level of error
checking and its use is encouraged.
FORTUNE.DOC 12 Jul 31, 1997
Return codes:
FORTUNE returns the following ERRORLEVEL codes:
0 = no problems, files found and batch file created
1 = no problems, no files met specifications
250 = operation aborted by pressing Escape
255 = syntax problems, file not found, or /? requested
Author:
This program was written by Bruce Guthrie of Wayne Software. It is free for
use and redistribution provided relevant documentation is kept with the
program, no changes are made to the program or documentation, and it is not
bundled with commercial programs or charged for separately. People who need to
bundle it in for-sale packages must pay a $50 registration fee to "Wayne
Software" at the following address.
Additional information about this and other Wayne Software programs can be
found in the file BRUCE.DOC which should be included in the original ZIP file.
The recent change history for this and the other programs is provided in the
HISTORY.ymm file which should be in the same ZIP file where "y" is replaced by
the last digit of the year and "mm" is the two digit month of the release;
HISTORY.611 came out in November 1996. This same naming convention is used in
naming the ZIP file (FORTNymm.ZIP) that this program was included in.
Comments and suggestions can also be sent to:
Bruce Guthrie
Wayne Software
113 Sheffield St.
Silver Spring, MD 20910
e-mail: WayneSof@erols.com fax: (301) 588-8986
http://www.geocities.com/SiliconValley/Lakes/2414
Please provide an Internet e-mail address on all correspondence.